package jay.home.bet.web.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jay.home.bet.domain.Item;
import jay.home.bet.domain.Order;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

public class CancelItemAction extends BaseAction
{
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws Exception
	{
		DynaActionForm df = (DynaActionForm) form;
		String itemid = df.getString("itemid");
		if(itemid == null)return mapping.findForward("SUCCESS");
		Order order = (Order)request.getSession().getAttribute("cart");
		if(order == null)return mapping.findForward("SUCCESS");
		if(order.getItems().size() <= 1)return mapping.findForward("SUCCESS");
		for(Item item : order.getItems())
			if(itemid.equalsIgnoreCase(item.getId()))order.getItems().remove(item);
		return mapping.findForward("SUCCESS");
	}
}
